#include <tsin/library/Trigger.hpp>

using namespace tsin;

char Trigger::getDescriptor()
{
        return 'P';
}

DynamicEvent Trigger::postTick(void *, void *)
{
        static bool firstTriggered = false;
        static bool ended = false;
        DynamicEvent ret = EVENT_NONE;
        if (!ended && trigger()) {
                ret |= EVENT_TRIGGER;
                if (firstTriggered) {
                        DynamicEvent e = DynamicObject::postTick();
                        if (e & EVENT_END)
                                ended = true;
                }
        }
        firstTriggered = true;
        return ret;
}
